package simonby.top.annualring.infrastructure.repository;

import simonby.top.annualring.domain.model.User;
import simonby.top.annualring.domain.repository.UserRepository;
import org.springframework.stereotype.Repository;
import simonby.top.annualring.infrastructure.dao.UserDao;

import java.util.List;
import java.util.Optional;

/**
 * 用户仓储的实现
 */
@Repository
public class UserRepositoryImpl implements UserRepository {
    private final UserDao userDao;

    public UserRepositoryImpl(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public User save(User user) {
        return userDao.save(user);
    }

    @Override
    public Optional<User> findById(Long id) {
        return userDao.findById(id);
    }

    @Override
    public Optional<User> findByUsername(String username) {
        return userDao.findByUsername(username);
    }

    @Override
    public List<User> findAll() {
        return userDao.findAll();
    }

    @Override
    public void deleteById(Long id) {
        userDao.deleteById(id);
    }

    @Override
    public Optional<User> findByEmail(String email) {
        return userDao.findByEmail(email);
    }
}